let app = getApp()

export function isLogin() {
	if (null == app.globalData.user.userOpenid || '' == app.globalData.user.userOpenid) {
		uni.showToast({
			title: '请先登录',
			position: 'bottom',
			icon: 'none',
			duration: 1000
		})

		setTimeout(() => {
			uni.navigateTo({
				url: '/pages/login/login?hot=0'
			})
		}, 200)

		return false;
	}

	let dateBegin = uni.getStorageSync('lastLoginTime')
	let dateEnd = new Date().getTime();
	if(dateBegin) {
		let dateDiff = dateEnd - dateBegin; //时间差的毫秒数
		let dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
		let minDiff = Math.floor(dateDiff / (60 * 1000)); //计算出相差天数
		console.log("minDiff: ", minDiff); //TODO 此处改为了分钟差以便测试
		if (dayDiff > 1) {
			uni.showToast({
				title: '登录超时',
				position: 'bottom',
				icon: 'none',
				duration: 1000
			})
			setTimeout(() => {
				uni.navigateTo({
					url: '/pages/login/login?hot=1'
				})
			}, 200)
		
			return false;
		} else {
			console.log("账户已登录 ");
			return true;
		}
	} else {
		console.log('无法获取上次登录时间');
		uni.showToast({
			title: '请先登录',
			position: 'bottom',
			icon: 'none',
			duration: 1000
		})
		setTimeout(() => {
			uni.navigateTo({
				url: '/pages/login/login?hot=0'
			})
		}, 200)
	}
	
	
	


}

export function getUserScore() {
	
}
